from multiprocessing import Queue

if __name__ == '__main__':
    q = Queue(3)
    print('队列是否为空', q.empty())
    print('队列是否为满', q.full())

    q.put('hello')
    q.put('world')
    print('队列是否为空', q.empty())
    print('队列是否为满', q.full())

    q.put('python')
    print('队列是否为空', q.empty())
    print('队列是否为满', q.full())
    print('队列中消息个数：', q.qsize())

    # 出队
    print(q.get())  # 拿出第一个消息 hello
    print('队列中消息个数：', q.qsize())

    # 入队
    q.put_nowait('java')
    # q.put_nowait('sql') # 队列已经满了，放不进去就报错
    # q.put('php')  # 区别是，会一直等待有空位置再放进去，不会报错

    # 遍历
    if not q.empty():
        for i in range(q.qsize()):
            print(q.get_nowait())

    print('队列是否为空', q.empty())
    print('队列是否为满', q.full())
    print('队列中消息个数：', q.qsize())

